package com.safety51.bootstrap.demo.interfaces;

import com.safety51.bootstrap.api.demo.student.StudentDTO;
import com.safety51.bootstrap.commons.context.UserInfoContext;
import com.safety51.bootstrap.commons.exception.BizzException;
import com.safety51.bootstrap.demo.domain.example.UserService;
import com.safety51.bootstrap.demo.domain.student.MultiDataSourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * Created by liuyuancheng on 2021/7/15  <br/>
 *
 * @author jerrylau
 */
@RestController
@RequestMapping("")
@Slf4j
public class DemoController {

    @Autowired
    private MultiDataSourceService dataSourceExample;

    @GetMapping("exception")
    public String exception() {
        throw new BizzException("exception advice test");
    }

    @GetMapping("/list")
    public List<String> datasources() {
        log.error("test error");
        return dataSourceExample.dataSources();
    }

    @GetMapping("/bool")
    public Boolean bool(){
        return true;
    }

    @GetMapping("/string")
    public String string(){
        return "teststring";
    }

    @GetMapping("mapList")
    public List<HashMap<String, String>> mapList() {
        return new ArrayList<HashMap<String, String>>() {{
            add(new HashMap<String, String>() {{
                put("name", "dog");
                put("age", "11");
            }});
            add(new HashMap<String, String>() {{
                put("name", "cat");
                put("age", "12");
            }});
        }};
    }

    @GetMapping(value = "")
    public String hello() {
        return "hello";
    }

    @GetMapping(value = "dto")
    public StudentDTO dto(){
        return null;
//        return new StudentDTO()
//                .setName("阿斯蒂芬阿萨德法律就")
//                .setId(1)
//                .setDateOfBirth("asdf");
    }

    @Autowired
    private UserService userService;
    @GetMapping("getUserInfo")
    public UserInfoContext.UserInfo getUserInfo(){
        return userService.getUserInfo();
    }
}
